<?php 
require_once 'ckLogin.php';
require_once 'init.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$db = new dbConn();
//删除
if(!empty($_GET['act'])){
	$act = $_GET['act'];
	if($act == 'del'){
		$db->sql = "UPDATE virtualuser SET `status` = 0 WHERE id = ".$_GET['id'];
		$db->doExecute();
	}
}
//提交处理
if(strtoupper($_SERVER['REQUEST_METHOD'])=='POST'){
	$comment = $_POST['comment'];
	$commentID = $_POST['commentID'];
	$db->sql="UPDATE `comment` SET `comment` = '".$comment."' WHERE id = ".$commentID;
	$db->doExecute();
}
//总条数
$db->sql="SELECT COUNT(id) FROM virtualuser WHERE `status`=1 ";
$count = $db->doResultOne();
//分页
if(empty($_GET['page'])){$page = 1;}else{$page=$_GET['page'];}
if(empty($_GET['pagesize'])){$pagesize = 45;}
else{$pagesize = $_GET['pagesize'];}
$pageInfo = page($count, $pagesize, $page);
$maxPage = $pageInfo['maxPage'];
$start = $pageInfo['start'];
$pages = $pageInfo['pages'];
//var_dump($pageInfo);

$db->sql="SELECT * FROM virtualuser WHERE `status`=1 LIMIT ".$start.",".$pagesize;
$comments = $db->doResultList2();
//分页
function page($total,$size,$page){
	//最大页数
	if($total%$size==0){
		$maxPage = $total/$size;
	}else{
		$maxPage = (int)($total/$size)+1;
	}
	//开始条数
	$start = ($page-1)*$size;
	//分页
	if($maxPage>=5){
		if($page<=2){
			$pages=array(1,2,3,4,5);
		}elseif($page>=($maxPage-1)){
			$pages=array($maxPage-4,$maxPage-3,$maxPage-2,$maxPage-1,$maxPage);
		}else{
			$pages=array($page-2,$page-1,$page,$page+1,$page+2);
		}
	}else{
		for($i=1;$i<=$maxPage;$i++){
			$pages[]=$i;
		}
	}
	if($page<=1){$previous=1;}else{$previous=$page-1;}
	if($page>=$maxPage) {$next = $maxPage;}else{ $next = $page+1;}
	return array('maxPage'=>$maxPage,'start'=>$start,'pages'=>$pages,'previous'=>$previous,'next'=>$next);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo APPLICATION;?></title>
<!--                       CSS                       -->
<!-- Reset Stylesheet -->
<link rel="stylesheet" href="resources/css/reset.css" type="text/css" media="screen" />
<!-- Main Stylesheet -->
<link rel="stylesheet" href="resources/css/main.css" type="text/css" media="screen" />
<!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
<link rel="stylesheet" href="resources/css/invalid.css" type="text/css" media="screen" />

<!-- jQuery -->
<script type="text/javascript" src="resources/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function($) {

	$(".comment-edit").click(function(){
		var id = $(this).parents("tr").children("td").eq(0).text();
		var comment = $(this).parents("tr").children("td").eq(1).text();
		$("#comment").text(comment);
		$("#commentID").val(id);
		$("#message_click").click();
	});
	$(".deleteUser").click(function(){
		if(!confirm("是否将此用户头像删除?")){
			return false;
		}
	});

});
</script>
<!-- jQuery Configuration -->
<script type="text/javascript"
	src="resources/scripts/simpla.jquery.configuration.js"></script>
<!-- Facebox jQuery Plugin -->
<script type="text/javascript" src="resources/scripts/facebox.js"></script>
<!-- jQuery WYSIWYG Plugin -->
<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
<style>
.box { 
width:85.5%; 
border:1px solid #ccc; 
background:#fff; 
margin:0px auto; 
padding:0px; 
} 
.image { 
float:left; 
border:1px solid #ccc; 
margin:3px 3px; 
padding:2px; 
display: inline;
text-align:center;
} 
.image img{
width: 50px; 
height: 50px;
}
.del{
	font-size:9px;
}
</style>
</head>

<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		<a href="#messages" rel="modal" id="message_click"></a>
		<div id="messages" style="display: none;">
			<!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->

			<p style="">
				<strong>简短描述输入及修改</strong>
			</p>
			<form action="<?php echo "?page=".$page;?>" method="post">
				<fieldset>
					描述：
					<textarea class="textarea" id="comment" name="comment" cols="79" rows="5"></textarea>
					<input id="commentID" name="commentID" type="hidden" value="" />
					<input class="button" type="submit" value="修改" /> 
					<a href="javascript:void(0);" onclick="$(this).parents('#facebox').hide();">关闭</a>
				</fieldset>
			</form>
		</div>
		<!-- End #messages -->
		<div id="main-content">
			<!-- Page Head -->
			<h2>欢迎使用<?php echo APPLICATION;?>管理后台</h2>
			<p id="page-intro">用户管理</p>

			<div class="clear"></div>
			<!-- End .clear -->

			<div class="content-box">
				<!-- Start Content Box -->
				
				<div class="content-box-header">
					<h3>虚拟头像</h3>
					<div class="clear"></div>

				</div>
				<!-- End .content-box-header -->

				<div class="content-box-content">

				<!-- Start Notifications -->
				
				<div class="notification success png_bg" style="display: none;">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
						修改成功
					</div>
				</div>
				
				<div class="notification error png_bg" style="display: none;">
					<a href="#" class="close"><img
						src="resources/images/icons/cross_grey_small.png"
						title="Close this notification" alt="close" /></a>
					<div>
					修改失败
					</div>
				</div>
				
				<!-- End Notifications -->
				
					<div class="tab-content default-tab" id="tab1">
						<!-- This is the target div. id must match the href of this div's tab -->

						<table>
							<thead>
								<tr>
									<td >
									<div class="notification information png_bg">
										<a href="#" class="close"><img
											src="resources/images/icons/cross_grey_small.png"
											title="Close this notification" alt="close" /></a>
										<div>
											虚拟头像上传遵照商品上传规则。即目录content/virtualuser/日期。日期大于等于当前日期即可。
										</div>
									</div>
									<?php if($maxPage>0):?>
										<div class="pagination" style="text-align: center;">
											<a href="?page=1" title="First Page">&laquo; First</a>
											<a href="?page=<?php echo  $pageInfo['previous'];?>" title="Previous Page">&laquo; Previous</a>
											<?php foreach ($pages as $item):?> 
											<a href="?page=<?php echo $item;?>" class="number <?php if($item == $page) echo 'current';?>" title="<?php echo $item;?>"><?php echo $item;?></a>
											<?php endforeach;?>
											<a href="?page=<?php echo $pageInfo['next'];?>" title="Next Page">Next &raquo;</a>
											<a href="?page=<?php echo $maxPage;?>" title="Last Page">Last &raquo;</a>
											total : <?php echo $maxPage;?>
										</div> 
									<?php endif;?>
									</td>
								</tr>
							</thead>
							<tbody>
							<?php if(count($comments)>0):?>
								<tr >
									<td >
										<div class="box"> 
											<?php foreach ($comments as $key=>$item):?>
											<div class="image">
												<div><img src="<?php echo '../'.$item['pic'];?>"></div>
												<div class="del"><a class="deleteUser" href="?act=del&id=<?php echo $item['id'];?>&page=<?php echo $page;?>">删除</a></div>
											</div>
											<?php endforeach;?>
											<div class="clear"></div>
										</div>
									</td>
								</tr>
							<?php else:?>
								<tr style="font-size: 50px;text-align: center; font-weight: bold;"><td colspan="5" style="text-align: center;">没有用户</td></tr>
							<?php endif;?>
							</tbody>
							<tfoot>
								<tr>
									<td >
									<?php if($maxPage>0):?>
										<div class="pagination" style="text-align: center;">
											<a href="?page=1" title="First Page">&laquo; First</a>
											<a href="?page=<?php echo  $pageInfo['previous'];?>" title="Previous Page">&laquo; Previous</a>
											<?php foreach ($pages as $item):?> 
											<a href="?page=<?php echo $item;?>" class="number <?php if($item == $page) echo 'current';?>" title="<?php echo $item;?>"><?php echo $item;?></a>
											<?php endforeach;?>
											<a href="?page=<?php echo $pageInfo['next'];?>" title="Next Page">Next &raquo;</a>
											<a href="?page=<?php echo $maxPage;?>" title="Last Page">Last &raquo;</a>
											total : <?php echo $maxPage;?>
										</div> 
									<?php endif;?>
									</td>
								</tr>
							</tfoot>
						</table>

					</div>
					<!-- End #tab2 -->

				</div>
				<!-- End .content-box-content -->

			</div>
			<!-- End .content-box -->

			<div class="clear"></div>

			<div id="footer">
				<small> <!-- Remove this notice or replace it with whatever you want -->
					&#169; Copyright 2009 Your Company | Powered by <a
					href="http://themeforest.net/item/simpla-admin-flexible-user-friendly-admin-skin/46073">Simpla
						Admin</a> | <a href="#">Top</a>
				</small>
			</div>
			<!-- End #footer -->

		</div>
		<!-- End #main-content -->

	</div>
</body>


<!-- Download From www.exet.tk-->
</html>
